package HCI.src;

import org.w3c.dom.Text;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.text.SpannableString;
import android.text.style.*;
//import android.text.style.TextAppearanceSpan;
import android.text.style.UnderlineSpan;
import android.text.util.Linkify;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

public class Description extends Activity {
    /** Called when the activity is first created. */
	
	Connector toDataBase;
	Connector photoName;
	TextView photoToolsLink;
	TextView photoIngredientsLink;
	
    public void onCreate(Bundle savedInstanceState, String recipeChosen) {
    	
        super.onCreate(savedInstanceState);
        setContentView(R.layout.descreption);
        
        OnClickListener ingredientsListner=new OnClickListener() {
        	// TODO Auto-generated method stub
			@Override
			public void onClick(View arg0) {
				
				toDataBase = new Connector("SELECT ing_name FROM ingredient i, ing_rcpe ir, recipe r WHERE i.ing_id = ir.ing_id, ir.rcpe_id = r.rcpe_id, r.rcpe_name = receipeChosen;");
				
				String ing = toDataBase+" \n ";
				 
				photoIngredientsLink.setText("Click Me to view Photos");
				photoIngredientsLink.setVisibility(1);
				photoToolsLink.setVisibility(0);
				
				SpannableString content=new SpannableString(ing);
					//content.setSpan(new Description(), 0, ing.length(), 0);
					((TextView)findViewById(R.id.ingredients)).setText(content);
					((TextView)findViewById(R.id.tools)).setText("");
					((TextView)findViewById(R.id.description)).setText("");
			}
		};
		((Button)findViewById(R.id.ingredientsButton)).setOnClickListener(ingredientsListner);
    
		
    OnClickListener toolsListner=new OnClickListener() {
	
		public void onClick(View arg0) {
			// TODO Auto-generated method stub
			//get the tools name 
			
			toDataBase = new Connector("SELECT tl_name FROM tool t, tl_rcpe tool, recipe r  WHERE t.tl_id = tool.tl_id, tool.rcpe_id = r.rcpe_id, r.rcpe_name =  receipeChosen;");
			String tools = toDataBase+" \n ";
			
			photoToolsLink.setText("Click Me to view Photos");
			photoToolsLink.setVisibility(1);
			photoIngredientsLink.setVisibility(0);
			
			SpannableString content=new SpannableString(tools);
			((TextView)findViewById(R.id.tools)).setText(content);
			((TextView)findViewById(R.id.ingredients)).setText("");
			((TextView)findViewById(R.id.description)).setText("");
		}
	};
	((Button)findViewById(R.id.toolsButton)).setOnClickListener(toolsListner);
	
	
	OnClickListener photosToolsListner=new OnClickListener() {
		
		public void onClick(View arg0) {
			//Toast is to appear and show the image and the name
			
			//toDataBase = new Connector("SELECT tools FROM recipes r WHERE r.name = receipeChosen;");
			//photoName = new Connector("SELECT photoTools FROM recipes r WHERE r.name = receipeChosen;");
			
			ImageButton imageToView;
//ImageButton result2 = (ImageButton)findViewById(R.id.SearchResult2ImageButton);
//ImageView image = (ImageView)photoName;
			/*Image image = (ImageView) layout.findViewById(R.id.image);
			image.setImageResource(R.drawable.android);
			TextView text = (TextView) layout.findViewById(R.id.text);
			text.setText("Hello! This is a custom toast!");

			Toast toast = new Toast(getApplicationContext());
			toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
			toast.setDuration(Toast.LENGTH_LONG);
			toast.setView(layout);
			toast.show();*/
			
			Toast.makeText(getBaseContext(), " The image should appear here ", Toast.LENGTH_LONG).show();
		}
	};
	photoToolsLink.setOnClickListener(photosToolsListner);

OnClickListener photosIngredientsListner=new OnClickListener() {
		
		public void onClick(View arg0) {
			//Toast is to appear and show the image and the name
			
			//toDataBase = new Connector("SELECT ingredients FROM recipes r WHERE r.name = receipeChosen;");
			//photoName = new Connector("SELECT photoTools FROM recipes r WHERE r.name = receipeChosen;");
			
			
			//ImageView image = (ImageView)photoName;
			/*Image image = (ImageView) layout.findViewById(R.id.image);
			image.setImageResource(R.drawable.android);
			TextView text = (TextView) layout.findViewById(R.id.text);
			text.setText("Hello! This is a custom toast!");

			Toast toast = new Toast(getApplicationContext());
			toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
			toast.setDuration(Toast.LENGTH_LONG);
			toast.setView(layout);
			toast.show();*/
			
			Toast.makeText(getBaseContext(), " The image of the ingredients ", Toast.LENGTH_LONG).show();
		}
	};
	photoIngredientsLink.setOnClickListener(photosIngredientsListner);

	
    OnClickListener descriptionListner=new OnClickListener() {
		@Override
		public void onClick(View arg0) {
			// TODO Auto-generated method stub
			toDataBase = new Connector("SELECT rcpe_dscrption FROM recipe r WHERE r.rcpe_name = receipeChosen;");
			String des = toDataBase+" \n";
			
			photoToolsLink.setVisibility(0);
			photoIngredientsLink.setVisibility(0);
			
			SpannableString content=new SpannableString(des);
			content.setSpan(new ForegroundColorSpan(Color.rgb(255, 0, 255)), 0, content.length(), 0);
		
		}
	};
	((Button)findViewById(R.id.descButton)).setOnClickListener(descriptionListner);
	
	
	OnClickListener playButton=new OnClickListener() {
		
		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			Intent dst=new Intent(v.getContext(),Video.class);
			startActivity(dst);
		}
	};
	((Button)findViewById(R.id.playVideoButton)).setOnClickListener(playButton);
	
	OnClickListener signOutListener=new OnClickListener() {
		
		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			Intent dst=new Intent(v.getContext(),HCI1Login.class);
			startActivity(dst);
		}
	};
	((Button)findViewById(R.id.signOutButton)).setOnClickListener(signOutListener);
 }	
}